package com.briup.jd2407cms.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.jd2407cms.aop.Logging;
import com.briup.jd2407cms.domain.DTO.LogExportParam;
import com.briup.jd2407cms.domain.DTO.LogParam;
import com.briup.jd2407cms.domain.VO.LogVO;
import com.briup.jd2407cms.service.LogService;
import com.briup.jd2407cms.util.excel.ExcelUtils;
import com.briup.jd2407cms.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @BelongsProject: JD2407-cms
 * @BelongsPackage: com.briup.jd2407cms.web.controller
 * @Author: 鲨鲨天下第一
 * @CreateTime: 2024-11-19  09:10
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "日志模块")
@RestController
@RequestMapping("/auth/log")
public class LogController {
    @Autowired
    private LogService logService;
    @Autowired
    private ExcelUtils excelUtils;

    @ApiOperation(value = "分页+条件查询日志信息", notes = "用户名、时间范围可以为空")
    @Logging("分页+条件查询日志信息")
    @PostMapping("/query")
    public Result query(@RequestBody LogParam param) {
        IPage<LogVO> page = logService.query(param);
        return Result.success(page);
    }

    //文件以响应 流的方式输出,不需要返回值
    @ApiOperation("导出日志信息")
//    @Logging("导出日志信息")
    @GetMapping(value = "/export", produces = "application/octet-stream")
    public Result export(HttpServletResponse response, LogExportParam logExportParam) {
        //1.获取数据
        List<LogVO> list = logService.queryForExport(logExportParam);
        //2.导出数据
        excelUtils.exportExcel(response, list, LogVO.class, "日志信息表");
        return Result.success("导出日志信息成功!");
    }
}
